package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.CancelTaskDto;
import com.zzyl.nursing.dto.NursingTaskChangeDto;
import com.zzyl.nursing.dto.NursingTaskExecutionDto;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.vo.NursingTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理任务Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/nursing/nursingTask")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 查询护理任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(NursingTask nursingTask) {
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        return getDataTable(list);
    }

    /**
     * 查询列表详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        NursingTaskVo task = nursingTaskService.selectNursingTaskById(id);
        return success(task);
    }

    /**=-----------------------------------------------
     *取消任务
     */
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody CancelTaskDto dto) {
        boolean success = nursingTaskService.cancelTask(dto.getTaskId(), dto.getReason());
        if (success) {
            return success();
        } else {
            return error("取消失败，请检查输入信息");
        }
    }

    /**
     * 执行任务
     */
    @PutMapping("/do")
    public AjaxResult execute(@RequestBody NursingTaskExecutionDto dto){
        nursingTaskService.execute(dto);
        return success();
    }

    /**
     * 任务改期
     */
    @PutMapping("/updateTime")
    public AjaxResult change(@RequestBody NursingTaskChangeDto dto){
        nursingTaskService.change(dto);
        return success();
    }
}
